package com.ebeitech.library.util;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

/**
 * Created by alice on 2017/10/25.
 */
public class VersionUtil {

	private static PackageInfo getPackageInfo(Context context) {
		try {
			PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
			return info;
		} catch (PackageManager.NameNotFoundException e) {
			e.printStackTrace();
		}
		return null;
	}

	public static String getVersionName(Context context) {
		PackageInfo info = getPackageInfo(context);
		if (info == null) {
			return "";
		}
		return info.versionName;
	}

	public static int getVersionCode(Context context) {
		PackageInfo info = getPackageInfo(context);
		if (info == null) {
			return 0;
		}
		return info.versionCode;
	}

}
